package com.abc.db;

import java.io.File;
import java.io.IOException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ExtDBHelper  {
	private SQLiteDatabase db ;  
	private static final String DATABASE_NAME = "easyclaim.db";
	private static final int DATABASE_VERSION = 1;
	public ExtDBHelper(Context context) {
		 String dbPath=android.os.Environment.getExternalStorageDirectory()
				 .getAbsolutePath()+"/database";
				         File dbp=new File(dbPath);
				         File dbf=new File(dbPath+"/"+DATABASE_NAME);

				                    
				         if(!dbp.exists()){
				                dbp.mkdir();
				          }
				                     
				         //数据库文件是否创建成功
				          boolean isFileCreateSuccess=false; 
				                     
				          if(!dbf.exists()){
				           try{                 
				                    isFileCreateSuccess=dbf.createNewFile();
				               }
				           catch(IOException ioex){
				                      
				              }
				                     
				           }
				             else{
				                     
				                     isFileCreateSuccess=true;
				               }
       if(isFileCreateSuccess)
    	   db = SQLiteDatabase.openOrCreateDatabase(dbf, null);
       db.execSQL("CREATE TABLE IF NOT EXISTS caze" +
				"(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, accidentDate VARCHAR, accidentAddress VARCHAR,lastModifyDate VARCHAR,carNumber VARCHAR,carOwnerName VARCHAR,carOwnerPhone VARCHAR,carOwnerAddr VARCHAR,insuranceNumber VARCHAR,note VARCHAR,officerName VARCHAR,officerNumber VARCHAR,important VARCHAR,location VARCHAR,carBrand VARCHAR)");

       db.execSQL("CREATE TABLE IF NOT EXISTS photo" +
				"(id INTEGER PRIMARY KEY AUTOINCREMENT,title VARCHAR, description VARCHAR,date VARCHAR,path VARCHAR, size VARCHAR, caseId INTEGER)");
       db.execSQL("CREATE TABLE IF NOT EXISTS text" +
				"(id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR, content VARCHAR,lastModifyDate VARCHAR, caseId INTEGER)");
       db.execSQL("CREATE TABLE IF NOT EXISTS record" +
				"(id INTEGER PRIMARY KEY AUTOINCREMENT,title VARCHAR,description VARCHAR, date VARCHAR, path VARCHAR,length VARCHAR,caseId INTEGER) ");
       
       //创建comment表
       db.execSQL("CREATE TABLE IF NOT EXISTS comment" +
    		   	"(id INTEGER PRIMARY KEY AUTOINCREMENT,date VARCHAR,content VARCHAR,type VARCHAR,caseId INTEGER)");
       //创建template表
       db.execSQL("CREATE TABLE IF NOT EXISTS template" +
    		   	"(id INTEGER PRIMARY KEY AUTOINCREMENT,content VARCHAR)");
       
       //创建photo表
       db.execSQL("CREATE TABLE IF NOT EXISTS photo"+
                "(id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR, description VARCHAR, date VARCHAR, path VARCHAR, size VARCHAR, caseId INTEGER)");
       //创建record表
       db.execSQL("CREATE TABLE IF NOT EXISTS record"+
               "(id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR, description VARCHAR, date VARCHAR, path VARCHAR, length INTEGER, caseId INTEGER)");
       
	}
	public SQLiteDatabase getWritableDatabase(){
		return db;
	}
}
